"""
https://leetcode.cn/problems/lian-biao-zhong-dao-shu-di-kge-jie-dian-lcof/description/

LCR 140. 训练计划 II
简单
相关标签
premium lock icon
相关企业
给定一个头节点为 head 的链表用于记录一系列核心肌群训练项目编号，请查找并返回倒数第 cnt 个训练项目编号。

 

示例 1：

输入：head = [2,4,7,8], cnt = 1
输出：8
 

提示：

1 <= head.length <= 100
0 <= head[i] <= 100
1 <= cnt <= head.length

"""

# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
from typing import Optional
from list_node import ListNode


class Solution:
    """
    和s019是完全一样的题目
    """
    def trainingPlan(self, head: Optional[ListNode], cnt: int) -> Optional[ListNode]:
        root=ListNode(0,head)
        slow=fast=root
        for i in range(cnt):
            fast=fast.next
        while fast:
            fast=fast.next
            slow=slow.next
        return slow